package com.common.config;

import com.ad.controller.ADController;
import com.common.controller.IndexController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.common.model.*;
import com.jfaker.framework.security.model.*;
import com.jfaker.framework.security.shiro.ShiroPlugin;
//import org.apache.log4j.Logger;

public class MainConfig extends JFinalConfig {
//	private static final Logger logger = Logger.getLogger("MainConfig");
	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
        PropKit.use("config.properties");
	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/mobile", IndexController.class);
		me.add("/ad", ADController.class);
	}
	
	public static C3p0Plugin createC3p0Plugin() {
		return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		// 配置C3p0数据库连接池插件
		C3p0Plugin C3p0Plugin = createC3p0Plugin();
		me.add(C3p0Plugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
		arp.setShowSql(true);
		arp.addMapping("user", User.class);
		arp.addMapping("users", Users.class);
		arp.addMapping("weiboInfo", WeiboInfo.class);
		arp.addMapping("sec_user", Admin.class);
		arp.addMapping("sec_resource", Resource.class);
		arp.addMapping("sec_org", Org.class);
		arp.addMapping("sec_role", Role.class);
		arp.addMapping("sec_authority", Authority.class);
		arp.addMapping("ad", ADModel.class);
		me.add(arp);
		
		//加载shiroPlugin插件
		ShiroPlugin shiroPlugin = new ShiroPlugin();
		me.add(shiroPlugin);

	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFinal.start("WebRoot", 2311, "/", 5);
	}
	
}
